package com.produce.system.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.produce.common.persistence.Page;
import com.produce.common.util.Md5Helper;
import com.produce.common.util.UUIDUtils;
import com.produce.system.dao.SysMenuDao;
import com.produce.system.dao.SysUserDao;
import com.produce.system.entity.SysUser;
import com.produce.system.service.SysUserService;

@Service("SysUserService")
public class SysUserServiceImpl implements SysUserService {
	@Resource
	private SysUserDao sysUserDao;
	@Resource
	private SysMenuDao sysMenuDao;
	/**
	 * 登录用户名数量验证
	 */
	@Override
	public int findCountByUsername(SysUser user) {
		return sysUserDao.findCountByUsername(user);
	}
	/**
	 * 登录用户名密码验证
	 */
	@Override
	public SysUser validatePassword(SysUser user) {
		SysUser validatedUser = new SysUser();
		validatedUser = sysUserDao.validatePassword(user);
		return validatedUser;
	}
	/**
	 * 登录查询所有菜单
	 */
	@Override
	public List<String> findMenuIdByUserId(String userId) {
		return sysMenuDao.findMenuIdByUserId(userId);
	}
	/**
	 * 用户列表显示
	 */
	@Override
	public Page<SysUser> findByPage(SysUser user, Page<SysUser> page) {
		page.setResult(sysUserDao.find(user, page));
		return page;
	}
	/**
	 * 新增
	 */
	@Override
	public void add(SysUser user) {
		user.setLoginpassword(Md5Helper.md5Str(user.getLoginpassword()));
		user.setUserid(UUIDUtils.getUUID());
		sysUserDao.add(user);
	}
	/**
	 * 带用户信息进修改页面
	 */
	@Override
	public SysUser getById(String id) {
		return  sysUserDao.getById(id);
	}
	/**
	 * 修改
	 */
	@Override
	public void update(SysUser user) {
		sysUserDao.update(user);
	}
	/**
	 * 删除用户
	 */
	@Override
	public void delete(String id) {
		sysUserDao.delete(id);
	}
	
}

